I am write procedure for write code sum of 1 to n numbers.
but It take more second to solve it.
like var a = 1 , var n = 12345678965487512 ,
var sum = 12345678965487513 ,
home / developersection / forums / write a program to find out the sum of 1 to n number which take minimum time to solve it.
I am write procedure for write code sum of 1 to n numbers.
but It take more second to solve it.
like var a = 1 , var n = 12345678965487512 ,
var sum = 12345678965487513 ,
Sanjay Goenka
06-Mar-2023I am writing a program in
JavaScriptlanguage.Output:
5050
Amrita Bhattacharjee
08-Feb-2023The program to find out sum of 1 to n number in python will be the following:
Rahul Roi
02-Feb-2023Output →
Input : 5
Output : Sum of first 5 natural numbers is: 15
This program take O(1) time.